ZIO Test: What, Why, and How?

您所在的位置:网站首页 scala zio ZIO Test: What, Why, and How?

ZIO Test: What, Why, and How?

#ZIO Test: What, Why, and How?| 来源: 网络整理| 查看: 265

Functional World meetup is a global event aimed at improving learning and knowledge sharing among developers with a passion for functional programming. This year’s edition was focused on the ZIO Scala library. In that vein, we invited developer and ZIO enthusiast Marcin Krykowski to speak about the functional power of ZIO Tests.

Marcin previously worked as a developer at Scalac. He is a poet at heart and believes that Scala and ZIO enable poetry through code. In addition, he recognizes the immense value of approaching software development problems from a beginner’s perspective. 

With that philosophy in mind, Marcin delivered an entry-level talk that’s accessible even to someone who has never encountered the ZIO Test framework before. 

His presentation is an “ultimate guide” to the ZIO Test framework. Marcin wanted to ensure that after finishing his talk, watchers would be ready for their journey with ZIO Test, meaning they would be able to import a project and run some initial tests. 

Marcin covered many aspects of the ZIO test framework and answered several important questions:

Answering Common Questions About ZIO TestHow do I start with ZIO Test?How do I write my first tests?How can I improve tests with ZIOTest?How do I use test effects with ZIO Test?How can I make tests more readable?How will my codebase benefit from ZIO Test?

With all that in mind, let’s dive into Macin’s presentation. He began by exploring some of the benefits of the ZIO Test compared to other frameworks. 

What Makes ZIO Test Better Than Other Frameworks?

You probably already have a set of preferred testing frameworks for use with your projects. So why should you invest time and effort in familiarizing yourself with a new one?

Marcin believes that employing ZIO Test is worthwhile because many frameworks suffer from the following problems:

Leaking resources: Some frameworks cause locking, which prevents other components from using a shared resource. A test may have acquired a resource and returned a result, but the resource may still be locked. Futures: Some test frameworks use futures as the main test effects. Multiple versions and platforms: If you’re coding using Scala, you shouldn’t use it as your main effect. This is because you likely work with various versions and platforms, such as Scala and ScalaJS. Rewriting specific tests for each platform wastes time. Instead, tests should be portable and work with more than one version.  Dependencies on other services: You may have to fetch code from different parts of the project to make tests work. Concurrency: ZIO Test allows multiple tasks to run at the same time. 

All of the issues described above, while not insurmountable, slow down the testing process. This costs time and money and affects client delivery. On the other hand, ZIO Test offers a range of functionalities that remedy these problems:

Functional effect systemsReferential transparencyResource safetyEnvironment typeInterruptibility

After outlining the benefits of the ZIO Test, Marcin delved into the specifics of setting up and running tests. 

How to Set Up a ZIO Test

To set up a ZIO test, first import the library dependency, as seen in the example below.

scala outsourcingHow to import ZIO Test 

Download the presentation in PDF

val zioVersion = "some_version" libraryDependencies ++= Seq( "dev.zio" %% "zio-test" % zioVersion % "test", "dev.zio" %% "zio-test-sbt" % zioVersion % "test" )trait TestAspect[+R0, -R1, +E0, -E1, +S0, -S1] { def apply[R >: R0 : E0 : S0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3